package com.dl7.playerdemo;

import com.bumptech.glide.Glide;
import com.dl7.player.media.IjkPlayerView;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.window.service.WindowManager;
import ohos.multimodalinput.event.KeyEvent;

public class IjkFullscreenActivity extends Ability {

    private static final String VIDEO_URL = "http://flv2.bn.netease.com/videolib3/1611/28/nNTov5571/SD/nNTov5571-mobile.mp4";
    private static final String IMAGE_URL = "http://vimg3.ws.126.net/image/snapshot/2016/11/C/T/VC628QHCT.jpg";
    IjkPlayerView mPlayerView;
    String rawFilePath = "/resources/rawfile/bili.xml";

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        WindowManager.getInstance().getTopWindow().get().setTransparent(true);
        mPlayerView = new IjkPlayerView(this);
        super.setUIContent(mPlayerView);
        Glide.with(this).load(IMAGE_URL).fitCenter().into(mPlayerView.mPlayerThumb);
        mPlayerView.init()
                .alwaysFullScreen()
                .enableOrientation()
                .setVideoPath(VIDEO_URL)
//                     屏蔽弹幕功能
//                    .enableDanmaku()
//                    .setDanmakuSource(getContext().getResourceManager().getRawFileEntry(rawFilePath).openRawFile())
                .setTitle("这是个跑马灯TextView，标题要足够长才会跑。-(゜ -゜)つロ 乾杯~ 乾杯~")
                .start();
        mPlayerView.initDamukuView("resources/rawfile/bili.xml");
    }

    @Override
    protected void onActive() {
        super.onActive();
        mPlayerView.onResume();
    }

    @Override
    protected void onInactive() {
        super.onInactive();
        mPlayerView.onPause();
    }

    @Override
    protected void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    protected void onBackground() {
        super.onBackground();
    }

    @Override
    protected void onStop() {
        super.onStop();
        mPlayerView.onDestroy();
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (mPlayerView.handleVolumeKey(keyCode)) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onBackPressed() {
        if (mPlayerView.onBackPressed()) {
            return;
        }
        super.onBackPressed();
    }
}
